<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\stage\controller;
use controller\BasicAdmin;
use service\DataService;
use service\ToolsService;
use think\Db;

class Order extends BasicAdmin
{

    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'php_order';

    /**
     * 用户列表
     * @return array|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\Exception
     */
    public function index()
    {
        $this->title = '订单列表';
        $post = $this->request->get();
        $db = Db::name($this->table);
        //过滤订单号
        if(isset($post['order_no']) && $post['order_no'] !== ''){
            $db->where(['order_no' => $post['order_no']]);
        }
       //过滤价格
        if(isset($post['sprice']) && $post['sprice'] !== ''){
            $db->where(['sprice' => $post['sprice']]);
        }

        //过滤支付状态
        if(isset($post['status']) && $post['status'] !== ''){
            $db->where(['status' => $post['status']]);
        }

        //过滤注册时间
        if(isset($post['create_at']) && $post['create_at'] !== ''){
            list($start,$end) = explode(' - ',$post['create_at']);
            $db->whereBetween('create_at', ["{$start} 00:00:00", "{$end} 23:59:59"]);
        }
        
        //统计总收入
         $data = Db::name($this->table)->where(['status' => 1])->column('sprice');
         $money = array_sum($data);
        return parent::_list($db->order('status asc,id desc'));
        //return parent::_list($db->order('status asc,id desc'),false,true,false);
    }


    /**
     * 删除
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        if (DataService::update($this->table)) {
            $this->success("删除成功！", '');
        }
        $this->error("删除失败，请稍候再试！");

    }
}
